package ${packageName}<#if moduleName??>.${moduleName}</#if>.service<#if subModuleName??>.${subModuleName}</#if>;

import ${packageName}<#if moduleName??>.${moduleName}</#if>.util.AssertUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import com.jk.global.model.result.PageResult;
import org.springframework.beans.BeanUtils;
import ${packageName}<#if moduleName??>.${moduleName}</#if>.entity<#if subModuleName??>.${subModuleName}</#if>.${ClassName};
import ${packageName}<#if moduleName??>.${moduleName}</#if>.model.request.${ClassName}Query;
import ${packageName}<#if moduleName??>.${moduleName}</#if>.model.${ClassName}VO;
import ${packageName}<#if moduleName??>.${moduleName}</#if>.mapper<#if subModuleName??>.${subModuleName}</#if>.${ClassName}Mapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * ${tableComment}
 *
 * @author ${author} ${email}
 * @since ${version} ${date}
 */
@Service
@Slf4j
@AllArgsConstructor
public class ${ClassName}Service {

    private final ${ClassName}Mapper ${className}Mapper;

    public PageResult<${ClassName}VO> queryPage(${ClassName}Query query) {
        AssertUtil.isNonNegative(query.getPageNumber(), "分页参数错误");
        AssertUtil.isNonNegative(query.getPageSize(), "分页参数错误");
        Page<${ClassName}> page = Page.of(query.getPageNumber(), query.getPageSize());
        LambdaQueryWrapper<${ClassName}> wrapper = Wrappers.lambdaQuery();
        Page<${ClassName}> pageResult = ${className}Mapper.selectPage(page, wrapper);
        return PageResult.of(pageResult.getTotal(), pageResult.getRecords());
    }

    public void insert(${ClassName}VO vo) {
        ${ClassName}  entity = new  ${ClassName}();
        BeanUtils.copyProperties(vo,entity);
        ${className}Mapper.insert(entity);
    }

    public void update(${ClassName}VO vo) {
        ${ClassName}  entity = new  ${ClassName}();
        BeanUtils.copyProperties(vo,entity);
        ${className}Mapper.updateById(entity);
    }

    public ${ClassName} query${ClassName}ById(Long id) {
        return ${className}Mapper.selectById(id);
    }

    @Transactional(rollbackFor = Exception.class)
    public void delete(List<Long> idList) {
        ${className}Mapper.deleteBatchIds(idList);
    }

}